package com.bjwl.dao.safty;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.alibaba.fastjson.JSONArray;
import com.bjwl.model.Module;
import com.bjwl.model.Role;
import com.bjwl.view.UserView;

public interface RoleDao {
	@Select("select * from sys_role")
	public List<Role> queryRole();

	@Update("update sys_role set ro_status=55 where ro_id=#{ro_id}")
	public int enableRole(Integer ro_id);
	
	@Update("update sys_role set ro_status=77 where ro_id=#{ro_id}")
	public int disableRole(Integer ro_id);

	@Insert("INSERT INTO sys_role VALUES(default,#{ro_name},#{ro_remark},#{ro_status})")
	public int addRole(Role role);

	@Update("update sys_role set ro_name=#{ro_name},ro_remark=#{ro_remark}, ro_status=#{ro_status} where ro_id=#{ro_id}")
	public int editRole(Role role);
	
	
	public List<Module> queryModuleAll();
	
	@Select("SELECT rm.m_id FROM `sys_rm` rm JOIN `sys_module` m WHERE rm.m_id=m.m_id AND rm.ro_id=#{ro_id} AND m.m_ismenu=1")
	public List<Integer> queryAllRoleById(Integer ro_id);

	@Delete("delete from sys_rm where ro_id=#{ro_id}")
	public int deleteRightByRoleId(Integer ro_id);

	@Insert("insert into sys_rm values(#{m_id},#{ro_id})")
	public int addRightByRoleId(Integer ro_id, Integer m_id);

	@Select("select ro_id from sys_ur where u_id=#{u_id}")
	public Integer getRoleIdByUserId(String u_id);
	
	@Select("select ro_name from sys_role where ro_id=#{ro_id}")
	public String getRoleByRoleId(Integer ro_id);
}
